import common from "common/common.js"
const state = {
	tabBarList: [{
		iconPath: "eye",
		selectedIconPath: "eye-fill",
		text: '发现音乐',
		customIcon: false,
		pagePath: "/pages/FindMusic/FindMusic"
	},
	// {
	// 	iconPath: "chat",
	// 	selectedIconPath: "chat-fill",
	// 	text: '动态',
	// 	customIcon: false,
	// 	pagePath: "pages/Dynamic/Dynamic"
	// },
	{
		iconPath: "account",
		selectedIconPath: "account-fill",
		text: '我的音乐',
		customIcon: false,
		pagePath: "/pages/MyMusic/MyMusic"
	}],
	commonColor: "#d43c33",
	openid: uni.getStorageSync('openid') || "",
	id: uni.getStorageSync('id') || "",//当前正在播放的音乐的id
	List: uni.getStorageSync('List') || [],//音乐列表
	index: uni.getStorageSync('index') || "", //被选中的歌曲的下标
	musicPlayingKey: uni.getStorageSync('musicPlayingKey') || false, //歌曲是否播放
	imgUrl: uni.getStorageSync('imgUrl') || "", //正在播放的歌曲的图片
	curPlayTime: uni.getStorageSync('curPlayTime') || 0, //正在播放的歌曲的当前时间
	sliderValue: uni.getStorageSync('sliderValue') || 0, //正在播放的歌曲的当前滚动条
	songSheetItem: uni.getStorageSync('songSheetItem'), //选中的歌单
	showPlayerMini: uni.getStorageSync('showPlayerMini') || false, //展示小播放器
	songSheetId: uni.getStorageSync('songSheetId') || "", //歌单id
	songSheetName: uni.getStorageSync('songSheetName') || "", //歌单名字
}

const getters= {
	curPlayTimeNum:(state) => {
		// let time = common.formatTime(statecurPlayTime);
		// console.log(ti,)
		// let regTime = new RegExp(time);
		// state.musicLyric.forEach(item => {
		// 	if(regTime.test(item)) {
		// 		this.lyricText = item.match(/\](.*)/)[1];
		// 		console.log(this.lyricText);
		// 	}
		// })
		console.log(state.curPlayTime);
		return common.formatTime(state.curPlayTime);
	}
}

const mutations = {
	SET_openid(state, openid) {//存储code
		console.log(openid);
		uni.setStorageSync('openid', openid);
		state.openid = openid;
	},
	SET_id(state, id) {//存储歌曲id
		uni.setStorageSync('id', id);
		state.id = id;
	},
	SET_List(state, List) {
		uni.setStorageSync("List", List);
		//uni.setStorageSync("index", index);
		state.List = List;
		//state.index = index;
	},
	SET_index(state, index) {
		uni.setStorageSync("index", index);
		state.index = index;
	},
	SET_musicPlayingKey(state, flag) {
		uni.setStorageSync("musicPlayingKey", flag);
		state.musicPlayingKey = flag;
	},
	SET_imgUrl(state, imgUrl) {
		uni.setStorageSync("imgUrl", imgUrl);
		state.imgUrl = imgUrl;
	},
	SET_curPlayTime(state, curPlayTime) {
		console.log(curPlayTime);
		uni.setStorageSync("curPlayTime", curPlayTime);
		state.curPlayTime = curPlayTime;
	},
	SET_sliderValue(state, sliderValue) {
		uni.setStorageSync("sliderValue", sliderValue);
		state.sliderValue = sliderValue;
	},
	SET_songSheetItem(state, songSheetItem) {
		uni.setStorageSync("songSheetItem", songSheetItem);
		state.songSheetItem = songSheetItem;
	},
	SET_showPlayerMini(state, showPlayerMini) {
		uni.setStorageSync("showPlayerMini", showPlayerMini);
		state.showPlayerMini = showPlayerMini;
	},
	SET_songSheetId(state, songSheetId) {
		uni.setStorageSync("songSheetId", songSheetId);
		state.songSheetId = songSheetId;
	},
	SET_songSheetName(state, songSheetName) {
		uni.setStorageSync("songSheetName", songSheetName);
		state.songSheetName = songSheetName;
	},
	// SET_musicLyric(state, musicLyric) {
	// 	uni.setStorageSync("musicLyric", musicLyric);
	// 	state.musicLyric = musicLyric;
	// },
	CLEAR_ALL(state) {
		state.openid= "";
		state.id = "";
		state.List = [];
		state.index = "";
		state.musicPlayingKey = false;
		state.imgUrl = "";
		state.curPlayTime = 0;
		state.sliderValue = 0;
		state.songSheetItem = "";
		state.showPlayerMini = false;
		// state.musicLyric = [];
		uni.clearStorageSync();
	}
}

const actions = {
	
}

export default {
	namespaced: true,
	state,
	mutations,
	actions,
	getters
}